﻿layui.use('layer', function () {
    var $ = layui.jquery, layer = layui.layer;
    var hasPassword = false;
    var hasSamePassword = false;
    var orderId = getUrlParam('orderId');
    $('#password').blur(function() {
        var password = $('#password').val();
        if (password.length != 6) {
            layer.tips('您的密码输入不正确', $('#password'));
        }
        else {
            hasPassword = true;
        }
    })

    $('#same_password').blur(function () {
        var password = $('#same_password').val();
        var samePassword = $('#password').val();
        if (password != samePassword) {
            layer.tips('两次输入的密码不同', $('#same_password'));
        }
        else if (password.length != 6) {
            layer.tips('您的密码输入不正确', $('#same_password'));
        } else {
            hasSamePassword = true;
        }
    })

    $('#pay_bt').click(function () {
        if (hasPassword && hasSamePassword) {
            var index = layer.load(2);
            $.ajax({
                url: '/Page/OrderPayment',
                type: "POST",
                data: {
                    password: $('#password').val(),
                    orderId:orderId,
                },
                success: function (data) {
                    layer.closeAll();
                    if (data.success != "") {
                        layer.msg(data.success);
                        location.href = "/ClientCenter/OrderList";
                    } else if (data.error != "") {
                        layer.msg(data.error);
                    }
                }
            })
        }
    })
})
